﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pay_My_Interface.Entity.Movement;

namespace Pay_My_Client.Static
{
    class Session
    {
        private static Session _session;

        private int nbJours = -1;
        private DateTime dateDebut;
        private DateTime dateFin;
        private List<IMovement> historique;
        private int o = 0;

        public static Session getSession()
        {
            if (_session == null)
                return startSession();
            return _session;
        }
        public static Session startSession()
        {
            if (_session == null || _session.getDateFin() != null)
                _session = new Session();
            return _session;
        }

        public static void startSession(int nbJours)
        {
            startSession();
            _session.nbJours = nbJours;
        }

        public static void stopSession()
        {
            if (_session != null)
                _session.dateFin = new DateTime();
        }

        private Session()
        {
            dateDebut = new DateTime();
        }

        public DateTime getDateDebut()
        {
            return dateDebut;
        }

        public DateTime getDateFin()
        {
            return dateFin;
        }

        public List<IMovement> getHistorique()
        {
            return (historique);
        }

        public void addMouvementDeFond(IMovement mouvementDeFond)
        {
            this.historique.Add(mouvementDeFond);
        }

        public bool iSWarningTime()
        {
            if (nbJours > 0)
            {
                int comp = Math.Abs(dateDebut.DayOfYear - (new DateTime()).DayOfYear);
                return comp > nbJours;
            }
            return false;
        }
    }
}
